; *** 15 Puzzle
; *** Copyright 1998-2002 Zillions Development
; v.2.0

; You need to purchase Zillions of Games to load this rules file
; Visit the Zillions web site at http://www.zillions-of-games.com
(translate
 ("8 Puzzle" "拼图3x3") ("15 Puzzle" "拼图4x4 一")
 ("Scramble A" "拼图4x4 二") ("Scramble B" "拼图4x4 三") ("Scramble C" "拼图4x4 四")
 ("14-15 Puzzle" "倒序拼图 4x4") ("Rotate 9" "滚动拼图 3x3")
)

(version "2.0")

(define step ($1 (verify empty?) add))
(define def-tile
    (name $1)
	(help "点击将其移动到相邻空格")
    (moves
	    (step n)
	    (step e)
	    (step s)
	    (step w)
    )
)
(define def-board-15
    (board
        (image "images\15_Puzzle\shaag\15puzzle.bmp" "images\15_Puzzle\15puzzle.bmp")
        (grid
            (start-rectangle 3 3 51 51); top-left position
            (dimensions ;4x4
                ("a/b/c/d" (50 0)) ; columns
                ("4/3/2/1" (0 50)) ; rows
			)
			(directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0))
		)
	)
)
(define def-15-common
	(description "你的目标图案如下：\\ 1   2   3   4\ 5   6   7   8\ 9  10 11 12\13 14 15\\
		图块只能横向或纵向移动。\由于显示答案需要读取标题，标题不能汉化。")
    (def-board-15)
	(win-condition 
	  (Self)
	  (and
        (absolute-config p1 (a4))
		(absolute-config p2 (b4))
		(absolute-config p3 (c4))
		(absolute-config p4 (d4))
		(absolute-config p5 (a3))
		(absolute-config p6 (b3))
		(absolute-config p7 (c3))
		(absolute-config p8 (d3))
		(absolute-config p9 (a2))
		(absolute-config p10 (b2))
		(absolute-config p11 (c2))
		(absolute-config p12 (d2))
		(absolute-config p13 (a1))
		(absolute-config p14 (b1))
		(absolute-config p15 (c1))
	  )
	)
)

(game
    (title "8 Puzzle")
	(solution "Solutions\15_Puzzle\8_Puzzle.zsg")
	(description "目标图案：\\1 2 3\4 5 6\7 8\\
              图块只能横向或纵向移动。")
    (history "Sam Loyd (1841-1911) was a famous inventor of puzzles.  He probably
             did not invent the Fifteen Puzzle, but popularized it and introduced
             a slight variant: His 14-15 puzzle was infamous, because it is impossible
             to solve!  A prize was offered of $1000 for the first correct solution
             to the problem, though of course it was never won.  Loyd wrote that 
             `...although there are thousands of persons who say they performed the
             required feat... none seem to be able to remember the sequence of moves
             whereby they feel sure they succeeded...`")
    (strategy "A good strategy is to solve the puzzle in numerical order, first getting
               the `1` tile in place, then the `2`, etc.  You may need to think ahead
               a bit to fit the final row in sequence.  In difficult situations it can
               be useful to order multiple tiles before putting them into place.\\To see
			   a solution, select `Show Solution` under the Help menu.  Can you do
			   better than this yourself?")
    (option "prevent flipping" true)
    (move-sound "Audio\\Click3.wav")
    (release-sound "Audio\\Click3.wav")
    (players Self)
    (turn-order Self)
    (board
        (image "images\15_Puzzle\shaag\9puzzle.bmp" "images\15_Puzzle\9puzzle.bmp")
        (grid
            (start-rectangle 3 3 51 51); top-left position
            (dimensions ;3x3
                ("a/b/c" (50 0)) ; columns
                ("3/2/1" (0 50)) ; rows
			)
			(directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0))
		)
	)
    (piece (image Self "images\15_Puzzle\shaag\1.bmp" "images\15_Puzzle\1.bmp")  (def-tile p1))
	(piece (image Self "images\15_Puzzle\shaag\2.bmp" "images\15_Puzzle\2.bmp")  (def-tile p2))
    (piece (image Self "images\15_Puzzle\shaag\3.bmp" "images\15_Puzzle\3.bmp")  (def-tile p3))
	(piece (image Self "images\15_Puzzle\shaag\4.bmp" "images\15_Puzzle\4.bmp")  (def-tile p4))
	(piece (image Self "images\15_Puzzle\shaag\5.bmp" "images\15_Puzzle\5.bmp")  (def-tile p5))
	(piece (image Self "images\15_Puzzle\shaag\6.bmp" "images\15_Puzzle\6.bmp")  (def-tile p6))
	(piece (image Self "images\15_Puzzle\shaag\7.bmp" "images\15_Puzzle\7.bmp")  (def-tile p7))
	(piece (image Self "images\15_Puzzle\shaag\8.bmp" "images\15_Puzzle\8.bmp")  (def-tile p8))
	(piece (image Self "images\15_Puzzle\shaag\9.bmp" "images\15_Puzzle\9.bmp")  (def-tile p9))
	(piece (image Self "images\15_Puzzle\shaag\10.bmp" "images\15_Puzzle\10.bmp") (def-tile p10))
    (piece (image Self "images\15_Puzzle\shaag\11.bmp" "images\15_Puzzle\11.bmp") (def-tile p11))
	(piece (image Self "images\15_Puzzle\shaag\12.bmp" "images\15_Puzzle\12.bmp") (def-tile p12))
	(piece (image Self "images\15_Puzzle\shaag\13.bmp" "images\15_Puzzle\13.bmp") (def-tile p13))
	(piece (image Self "images\15_Puzzle\shaag\14.bmp" "images\15_Puzzle\14.bmp") (def-tile p14))
	(piece (image Self "images\15_Puzzle\shaag\15.bmp" "images\15_Puzzle\15.bmp") (def-tile p15))
    (board-setup
        (Self  (p4 a1)
			   (p8 a2)
			   (p7 a3)
			   (p3 b2)
			   (p5 b3)
			   (p1 c1)
			   (p2 c2)
			   (p6 c3)
		)
		
	)
    (win-condition 
	  (Self)
	  (and
        (absolute-config p1 (a3))
		(absolute-config p2 (b3))
		(absolute-config p3 (c3))
		(absolute-config p4 (a2))
		(absolute-config p5 (b2))
		(absolute-config p6 (c2))
		(absolute-config p7 (a1))
		(absolute-config p8 (b1))
	  )
	)
)

(variant (title "-")) ; ---------------------------------------------------

(variant
    (title "15 Puzzle")
	(solution "Solutions\15_Puzzle\15_Puzzle.zsg")
    (def-15-common)
    (board-setup
        (Self  (p3 a1)
			   (p2 a2)
			   (p1 a3)
			   (p6 a4)
			   (p5 b1)
			   (p4 b2)
			   (p7 b3)
			   (p8 b4)
			   (p9 c1)
			   (p10 c2)
			   (p15 c3)
			   (p11 c4)
			   (p14 d3)
			   (p12 d2)
			   (p13 d1)				  			
		)
	)
)

(variant 
  (title "Scramble A")
  (solution "Solutions\15_Puzzle\Scramble_A.zsg")
  (def-15-common)
  (board-setup
        (Self  (p2 a1)
			   (p1 a2)
			   (p6 c4)
			   (p5 b1)
			   (p4 d3)
			   (p7 a4)
			   (p8 a3)
			   (p9 d2)
			   (p10 b4)
			   (p15 b2)
			   (p11 d4)
			   (p14 d1)
			   (p12 b3)
			   (p13 c3)
               (p3 c1)				  			
		)
	)
)

(variant 
  (title "Scramble B")
  (solution "Solutions\15_Puzzle\Scramble_B.zsg")
  (def-15-common)
  (board-setup
        (Self  (p2 a2)
			   (p1 c2)
			   (p6 d3)
			   (p5 a1)
			   (p4 d2)
			   (p7 c3)
			   (p8 a4)
			   (p9 c1)
			   (p10 a3)
			   (p15 b3)
			   (p11 b4)
			   (p14 d1)
			   (p12 c4)
			   (p13 d4)
               (p3 b2)				  			
		)
	)
)

(variant 
  (title "Scramble C")
  (solution "Solutions\15_Puzzle\Scramble_C.zsg")
  (def-15-common)
  (board-setup
        (Self  (p3 a1)
			   (p2 c1)
			   (p1 b1)
			   (p6 b2)
			   (p5 c2)
			   (p4 d2)
			   (p7 a2)
			   (p8 d3)
			   (p9 c3)
			   (p10 b3)
			   (p15 a4)
			   (p11 a3)
			   (p14 b4)
			   (p12 d4)
			   (p13 c4)
		)
	)
)

(variant (title "-")) ; ---------------------------------------------------

(variant 
   (title "14-15 Puzzle")
   (description "此图无法还原成右下角空格，但是可以还原成左上角空格。\\
	  所以你的目标图案是：\\      1   2   3\ 4   5   6   7\ 8   9  10 11\12 13 14 15")
   (solution "Solutions\15_Puzzle\14-15_Puzzle.zsg")
   (def-board-15)
   (board-setup
        (Self  (p1  a4) (p2  b4) (p3  c4) (p4  d4)
		       (p5  a3) (p6  b3) (p7  c3) (p8  d3)
			   (p9  a2) (p10 b2) (p11 c2) (p12 d2)
			   (p13 a1) (p15 b1) (p14 c1)
		)
	)
    (win-condition 
	  (Self)
	  (and
                                   (absolute-config p1  (b4)) (absolute-config p2  (c4)) (absolute-config p3  (d4))
		(absolute-config p4  (a3)) (absolute-config p5  (b3)) (absolute-config p6  (c3)) (absolute-config p7  (d3))
		(absolute-config p8  (a2)) (absolute-config p9  (b2)) (absolute-config p10 (c2)) (absolute-config p11 (d2))
		(absolute-config p12 (a1)) (absolute-config p13 (b1)) (absolute-config p14 (c1)) (absolute-config p15 (d1))
	  )
	)
)

(variant 
    (title "DEAD PIGS WONT FLY")
    (description "原始图案：\\D  E   A  D\P   I   G  S\W O  N  T\F   L   Y\\目标图案：\\D  E   A  D\P   I   G  S\F   L   Y\T  O  W N")
    (history "This tricky puzzle is based on Sam Loyd's original 14-15 puzzle.")
	(strategy "Yes, this puzzle is solvable!  Hint: carefully read the description of
	   the 14-15 Puzzle.")
    (solution "Solutions\15_Puzzle\DEAD_PIGS_WONT_FLY.zsg")
    (piece (image Self "images\15_Puzzle\shaag\A.bmp" "images\15_Puzzle\A.bmp") (def-tile A))
	(piece (image Self "images\15_Puzzle\shaag\D.bmp" "images\15_Puzzle\D.bmp") (def-tile D))
    (piece (image Self "images\15_Puzzle\shaag\E.bmp" "images\15_Puzzle\E.bmp") (def-tile E))
	(piece (image Self "images\15_Puzzle\shaag\F.bmp" "images\15_Puzzle\F.bmp") (def-tile F))
	(piece (image Self "images\15_Puzzle\shaag\I.bmp" "images\15_Puzzle\I.bmp") (def-tile I))
	(piece (image Self "images\15_Puzzle\shaag\G.bmp" "images\15_Puzzle\G.bmp") (def-tile G))
	(piece (image Self "images\15_Puzzle\shaag\L.bmp" "images\15_Puzzle\L.bmp") (def-tile L))
	(piece (image Self "images\15_Puzzle\shaag\N.bmp" "images\15_Puzzle\N.bmp") (def-tile N))
	(piece (image Self "images\15_Puzzle\shaag\O.bmp" "images\15_Puzzle\O.bmp") (def-tile O))
	(piece (image Self "images\15_Puzzle\shaag\P.bmp" "images\15_Puzzle\P.bmp") (def-tile P))
    (piece (image Self "images\15_Puzzle\shaag\S.bmp" "images\15_Puzzle\S.bmp") (def-tile S))
	(piece (image Self "images\15_Puzzle\shaag\T.bmp" "images\15_Puzzle\T.bmp") (def-tile T))
	(piece (image Self "images\15_Puzzle\shaag\W.bmp" "images\15_Puzzle\W.bmp") (def-tile W))
	(piece (image Self "images\15_Puzzle\shaag\Y.bmp" "images\15_Puzzle\Y.bmp") (def-tile Y))
    (def-board-15)
    (board-setup
        (Self  (D a4) (E b4) (A c4) (D d4)
		       (P a3) (I b3) (G c3) (S d3)
			   (W a2) (O b2) (N c2) (T d2)
			   (F a1) (L b1) (Y c1)
		)
	 )
     (win-condition 
	     (Self)
	     (and
           (absolute-config D (a4)) (absolute-config E (b4)) (absolute-config A (c4)) (absolute-config D (d4))
		   (absolute-config P (a3)) (absolute-config I (b3)) (absolute-config G (c3)) (absolute-config S (d3))
		   (absolute-config F (a2)) (absolute-config L (b2)) (absolute-config Y (c2))
		   (absolute-config T (a1)) (absolute-config O (b1)) (absolute-config W (c1)) (absolute-config N (d1))
	     )
	 )
)


(define def-ball
    (name $1)
	(help "Slide this ball to any free adjacent space")
    (moves
	    (step n)
	    (step e)
	    (step s)
	    (step w)
    )
)

(define def-board-6x2
    (board
        (image "images\15_Puzzle\shaag\6x2.bmp" "images\15_Puzzle\6x2.bmp")
        (grid
            (start-rectangle 3 3 52 52); top-left position
            (dimensions ;6x2
                ("a/b/c/d/e/f" (51 0)) ; columns
                ("1/2" (0 51)) ; rows
			)
			(directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0))
		)
	)
)

(variant 
   (title "Panama Canal")
   (description "目标图案：\\PANAMA\CANAL")
   (history "This puzzle was invented in 1915, around the time of the construction of the Panama Canal.")
   (strategy "Notice that there are several A's in the puzzle.  Exchanging those letters is one of the keys to
       solving it.  The included solution is 26 moves.")
   (solution "Solutions\15_Puzzle\Panama.zsg")
   (def-board-6x2)
   (piece
      (image Self "images\15_Puzzle\shaag\ao.bmp" "images\15_Puzzle\ao.bmp")
	  (def-ball A)
    )  
   (piece
      (image Self "images\15_Puzzle\shaag\co.bmp" "images\15_Puzzle\co.bmp")
	  (def-ball C)
   )
   (piece
      (image Self "images\15_Puzzle\shaag\mo.bmp" "images\15_Puzzle\mo.bmp")
	  (def-ball M)
   )
   (piece
      (image Self "images\15_Puzzle\shaag\llo.bmp" "images\15_Puzzle\llo.bmp")
	  (def-ball L)
   )
   (piece
      (image Self "images\15_Puzzle\shaag\no.bmp" "images\15_Puzzle\no.bmp")
	  (def-ball N)
   )
   (piece
      (image Self "images\15_Puzzle\shaag\po.bmp" "images\15_Puzzle\po.bmp")
	  (def-ball P)
   )
   (board-setup
        (Self  (C a1) (A b1) (N c1) (A d1) (M e1) (A f1) 
		       (P a2) (A b2) (N c2) (A d2) (L e2)
		)
   )
   (win-condition 
	  (Self)
	  (and
        (absolute-config P (a1))
		(absolute-config A (b1))
		(absolute-config N (c1))
		(absolute-config A (d1))
		(absolute-config M (e1))
		(absolute-config A (f1))
		(absolute-config C (a2))
		(absolute-config A (b2))
		(absolute-config N (c2))
        (absolute-config A (d2))
		(absolute-config L (e2))
	  )
	)
)


(variant (title "-")) ; ---------------------------------------------------

(define rotate ($1 cascade from $1 to cascade from $1 to add))
(define def-rotate-tile
    (name $1)
	(help "Slide this tile horizontally or vertically.")
    (moves
	    (rotate n)
	    (rotate e)
	    (rotate s)
	    (rotate w)
    )
)
(variant
    (title "Rotate 9")
	(solution "Solutions\15_Puzzle\Rotate_9.zsg")
    (move-sound "Audio\\Click3.wav")
    (release-sound "Audio\\Click3.wav")
	(description "目标：\\1 2 3\4 5 6\7 8 9\\
              每一行每一列都可以滚动。")
    (history "This is a new twist on the 15 Puzzle.  If you've ever worked at
	          solving a Rubik's Cube, you'll quickly see the similarity between
			  this puzzle and that one as well.")
    (players Self)
    (turn-order Self)
    (board
        (image "images\15_Puzzle\shaag\9puzzle.bmp" "images\15_Puzzle\9puzzle.bmp")
        (grid
            (start-rectangle 3 3 51 51); top-left position
            (dimensions ;3x3
                ("a/b/c" (50 0)) ; columns
                ("3/2/1" (0 50)) ; rows
			)
			(directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0))
		)
		(links n (a3 a1) (b3 b1) (c3 c1))
		(links s (a1 a3) (b1 b3) (c1 c3))
		(links e (c3 a3) (c2 a2) (c1 a1))
		(links w (a3 c3) (a2 c2) (a1 c1))
	)
    (piece (image Self "images\15_Puzzle\shaag\1.bmp" "images\15_Puzzle\1.bmp")  (def-rotate-tile p1))
	(piece (image Self "images\15_Puzzle\shaag\2.bmp" "images\15_Puzzle\2.bmp")  (def-rotate-tile p2))
    (piece (image Self "images\15_Puzzle\shaag\3.bmp" "images\15_Puzzle\3.bmp")  (def-rotate-tile p3))
	(piece (image Self "images\15_Puzzle\shaag\4.bmp" "images\15_Puzzle\4.bmp")  (def-rotate-tile p4))
	(piece (image Self "images\15_Puzzle\shaag\5.bmp" "images\15_Puzzle\5.bmp")  (def-rotate-tile p5))
	(piece (image Self "images\15_Puzzle\shaag\6.bmp" "images\15_Puzzle\6.bmp")  (def-rotate-tile p6))
	(piece (image Self "images\15_Puzzle\shaag\7.bmp" "images\15_Puzzle\7.bmp")  (def-rotate-tile p7))
	(piece (image Self "images\15_Puzzle\shaag\8.bmp" "images\15_Puzzle\8.bmp")  (def-rotate-tile p8))
	(piece (image Self "images\15_Puzzle\shaag\9.bmp" "images\15_Puzzle\9.bmp")  (def-rotate-tile p9))
    (board-setup
        (Self  (p4 a1)
			   (p9 a2)
			   (p7 a3)
			   (p8 b1)
			   (p3 b2)
			   (p5 b3)
			   (p1 c1)
			   (p2 c2)
			   (p6 c3)
		)
		
	)
    (win-condition 
	  (Self)
	  (and
        (absolute-config p1 (a3))
		(absolute-config p2 (b3))
		(absolute-config p3 (c3))
		(absolute-config p4 (a2))
		(absolute-config p5 (b2))
		(absolute-config p6 (c2))
		(absolute-config p7 (a1))
		(absolute-config p8 (b1))
	  )
	)
)


